<meta charset="utf-8" />
<div class="box box-primary" id="bizConfig">
<div class="box-body">
	<div class="col-lg-3 col-md-3 col-sm-4">
		<div class="panel panel-default">
			<div class="panel-heading">组织机构</div>
			<div class="panel-body" id="sysOrganizationTreeMenu">
				<km-tree host="baseServer" id="sysOrganizationTree" url="sys/sysOrganization/loadOrganizationTree" param="" chooseType="checkbox" isRightClick="true" onclick="loadSysOrganization"
				addChildNodeName="addPosition" editNodeName="edit" removeNodeName="deleteTree" openNum="4"></km-tree>
			</div>
		</div>
	</div>
	<div class="col-lg-9 col-md-9 col-sm-8">
		<form id="searchForm" role="form" class="form-inline" style="display: none;">
			<div class="box-body">
			</div>
			<button type="button" class="btn btn-info pull-right m-t-n-xs" onclick="search();">
				<strong>查询</strong>
			</button>
		</form>
		 <div class="box">
		<div class="box-body">
			<div class="row">
				<div class="col-md-12">
				    <div class="btn-group " id="sysOrganizationToolbar" role="group">
				                    <km-bt-add label="增加" onclick="addPosition();"></km-bt-add>
				                    <km-bt-edit label="编辑" onclick="editPosition();"></km-bt-edit>
				                    <km-bt-add label="人员分配" onclick="assign();"></km-bt-add>
                                    <km-bt-no label="停用" onclick="cancel();"></km-bt-no>
                                    <km-bt-yes label="启用" onclick="activate();"></km-bt-yes>
                                   
                           </div>

					<table id="sysOrganizationTable" data-mobile-responsive="true"></table>
				</div>
			</div>
		</div>
	</div>
</div>
</div>
 <script type="text/javascript">
var jqTableDom=$("#sysOrganizationTable");
var qid;
$(function() {
	loadSysOrganization();
	});
   function loadSysOrganization(id){
	   
	   var jqFormDom=$("#searchForm");
		var jqToolbarDom=$("#sysOrganizationToolbar");
		if(zfesUtil.isEmpty(id)){
			var url=host_auth+"/sys/sysPosition/loadPositionByOrgId";
		}else{
			var url=host_auth+"/sys/sysPosition/loadPositionByOrgId?organizationId="+id;
		}
		var columns=[
						{checkbox:true},
						{field:'name',title:'岗位名称',width:160,sortable:true},
						{field:'roleName',title:'对应的角色',width:160,sortable:true},
						{field:'orgName',title:'组织机构名称',width:200},
						{field:'remark',title:'备注',width:200},
						{field:'enabled',title:'是否可用',width:160,formatter:zfesUtil.formatBool}
					
					];
		bstable=zfesBstable.laodTable(jqTableDom,jqFormDom,jqToolbarDom,url,columns);
	}
   
   function cancel(){
	   if(zfesBstable.isOneRow(jqTableDom)){
			var row = zfesBstable.getSelections(jqTableDom);
			 if(row[0].enabled=='0'){
						alertSwal.warningTitle("该岗位已经是停用状态");
						 return false;
					 }
			var id=zfesBstable.getRowId(jqTableDom);
			var enabled="0";
			 alertSwal.confirm("注销","是否注销该岗位",function(){
				 	var ajaxUrl = host_auth+"/sys/sysPosition/updatePositionStatus";
					var param = { "id" : id,"enabled":enabled};
					zfesAjax.ajaxTodo(ajaxUrl, param, function(data) {
						alertSwal.successText(data.message);
		 			layer.close(layer.index);
		 			zfesBstable.refresh(jqTableDom);
					}); 
		});
			}
	   
   }
   function activate (){
	   if(zfesBstable.isOneRow(jqTableDom)){
			var row = zfesBstable.getSelections(jqTableDom);
			 if(row[0].enabled=='1'){
						alertSwal.warningTitle("该岗位已经为使用状态");
						 return false;
					 }
			 var id=zfesBstable.getRowId(jqTableDom);
			 var enabled="1";
			 alertSwal.confirm("启用","是否启用该状态",function(){
				 	var ajaxUrl = host_auth+"/sys/sysPosition/updatePositionStatus";
					var param = { "id" : id,"enabled":enabled};
					zfesAjax.ajaxTodo(ajaxUrl, param, function(data) {
						alertSwal.successText(data.message);
		 			layer.close(layer.index);
		 			zfesBstable.refresh(jqTableDom);
				}); 
		});
	   }
   }
   
   function editPosition(){
		 if(zfesBstable.isOneRow(jqTableDom)){
			 var id=zfesBstable.getRowId(jqTableDom);
			 var url="/view/auth/sysPosition/sysPosition.edit.html";
			 zfesLayerEditDg.open(url,{"id":id},"数据字典信息编辑",460,function(){zfesBstable.refresh(jqTableDom);}); 
		 }
   }
   
   function addPosition(){
	   var url="/view/auth/sysPosition/sysPosition.add.html";
	    zfesLayerEditDg.open(url,{"id":qid},"岗位信息编辑",400,function(){zfesBstable.refresh(jqTableDom);}); 
   }
   
   function assign(){
			 if(zfesBstable.isOneRow(jqTableDom)){
					var row = zfesBstable.getSelections(jqTableDom);
					 if(row[0].enabled=='0'){
								alertSwal.warningTitle("该岗位为禁用状态，不允许分配人员");
								 return false;
							 }
				 var id=zfesBstable.getRowId(jqTableDom);
				 var url="/view/auth/sysPosition/sysPositionAssign.html";
				 zfesLayerEditDg.open(url,{"id":id},"岗位信息编辑",1100,function(){zfesBstable.refresh(jqTableDom);}); 
			 }
   }
   
</script> 
</div>
